﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;
using YArchitech.MEP.Electric.Common;

namespace HYRElectric.WirePlace
{
	public partial class DlgPanelConnection : System.Windows.Forms.Form
	{
		public DlgPanelConnection()
		{
			this.InitializeComponent();
		}

		private void DlgPanelConnection_Load(object sender, EventArgs e)
		{
			this.xmlHelper.LoadXml(this.path, "Root");
			//base.Icon = Resource.YArchitechIcon;
			this.LoadDlgData();
			if (string.IsNullOrEmpty(this.txtWidth.Text))
			{
				this.txtWidth.Text = "200";
			}
			if (string.IsNullOrEmpty(this.txtHeight.Text))
			{
				this.txtHeight.Text = "50";
			}
			if (string.IsNullOrEmpty(this.txtLevel.Text))
			{
				this.txtLevel.Text = "2800";
			}
		}

		private void DlgPanelConnection_FormClosed(object sender, FormClosedEventArgs e)
		{
			this.SaveDlgData();
		}

		private void SaveDlgData()
		{
			this.xmlHelper.SelectNode(Path.Combine("Root", "HYPanelConnection"));
			this.xmlHelper.SelectNode(Path.Combine("Root", "HYPanelConnection", "Params"));
			this.xmlHelper.SetAttribute("Width", this.txtWidth.Text.Trim());
			this.xmlHelper.SetAttribute("Height", this.txtHeight.Text.Trim());
			this.xmlHelper.SetAttribute("Level", this.txtLevel.Text.Trim());
			this.xmlHelper.SaveXml("");
		}

		private void LoadDlgData()
		{
			this.xmlHelper.SelectNode(Path.Combine("Root", "HYPanelConnection", "Params"));
			this.txtWidth.Text = this.xmlHelper.GetAttribute("Width");
			this.txtHeight.Text = this.xmlHelper.GetAttribute("Height");
			this.txtLevel.Text = this.xmlHelper.GetAttribute("Level");
		}

		private void txtWidth_KeyPress(object sender, KeyPressEventArgs e)
		{
			Common.IsPlusDouble(e, this.txtWidth.Text);
		}

		private void txtHeight_KeyPress(object sender, KeyPressEventArgs e)
		{
			Common.IsPlusDouble(e, this.txtHeight.Text);
		}

		private void txtLevel_KeyPress(object sender, KeyPressEventArgs e)
		{
			Common.IsDouble(e, this.txtLevel);
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			if (Common.CheckValue(this.txtWidth, "宽度") && Common.CheckValue(this.txtHeight, "高度") && Common.CheckValue(this.txtLevel, "相对标高"))
			{
				base.DialogResult = DialogResult.OK;
			}
		}

		private YArchitech.MEP.Electric.Common.XmlHelper xmlHelper = new YArchitech.MEP.Electric.Common.XmlHelper();

		private string path = Path.Combine(Product.WorkingLocation, "PanelConnection.xml");

		private const string Root = "Root";

		private const string Node = "HYPanelConnection";

		private const string ChildNode = "Params";

		private new const string Width = "Width";

		private new const string Height = "Height";

		private const string Level = "Level";
	}
}
